﻿Public Class ctrChucVu_BangCap

    Private Sub ctrChucVu_BangCap_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        gvBangCap_Load()
        gvChucVu_Load()
    End Sub

    Private Sub btnThoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThoat.Click
        frmMain.TabControl1.TabPages.Remove(frmMain.TabControl1.SelectedTab)
    End Sub

    'XU LY GROUP BANG CAP
    Public Sub gvBangCap_Load()
        Dim bus As BangCapBUS = New BangCapBUS()
        gvBangCap.DataSource = bus.GetTable()
    End Sub

    Private Sub btnThemBC_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThemBC.Click
        Dim tmp As BangCapDTO = New BangCapDTO()
        tmp.TenBC = txtTenBC.Text

        Dim bus As BangCapBUS = New BangCapBUS()
        bus.Insert(tmp)
        gvBangCap_Load()
    End Sub

    Private Sub btnLamMoiBC_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLamMoiBC.Click
        txtTenBC.Text = ""
    End Sub

    Private Sub btnSuaBC_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSuaBC.Click
        Dim tmp As BangCapDTO = New BangCapDTO()
        tmp.MaBC = gvBangCap.CurrentRow.Cells(0).Value.ToString()
        tmp.TenBC = txtTenBC.Text

        Dim bus As BangCapBUS = New BangCapBUS()
        bus.Update(tmp)
        gvBangCap_Load()
    End Sub

    Private Sub btnXoaBC_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXoaBC.Click
        Dim tmp As BangCapDTO = New BangCapDTO()
        tmp.MaBC = gvBangCap.CurrentRow.Cells(0).Value.ToString()

        Dim bus As BangCapBUS = New BangCapBUS()
        bus.Delete(tmp)
        gvBangCap_Load()
    End Sub

    Private Sub gvBangCap_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles gvBangCap.SelectionChanged
        If gvBangCap.CurrentRow IsNot Nothing Then
            txtTenBC.Text = gvBangCap.CurrentRow.Cells(1).Value.ToString()
        End If
    End Sub

    'XU LY GROUP CHUC VU
    Public Sub gvChucVu_Load()
        Dim bus As ChucVuBUS = New ChucVuBUS()
        gvChucVu.DataSource = bus.GetTable()
    End Sub

    Private Sub btnThemCV_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThemCV.Click
        Dim tmp As ChucVuDTO = New ChucVuDTO()
        tmp.TenCV = txtTenCV.Text

        Dim bus As ChucVuBUS = New ChucVuBUS()
        bus.Insert(tmp)
        gvChucVu_Load()
    End Sub

    Private Sub btnLamMoiCV_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLamMoiCV.Click
        txtTenCV.Text = ""
    End Sub

    Private Sub btnSuaCV_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSuaCV.Click
        Dim tmp As ChucVuDTO = New ChucVuDTO()
        tmp.MaCV = gvChucVu.CurrentRow.Cells(0).Value.ToString()
        tmp.TenCV = txtTenCV.Text

        Dim bus As ChucVuBUS = New ChucVuBUS()
        bus.Update(tmp)
        gvChucVu_Load()
    End Sub

    Private Sub btnXoaCV_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXoaCV.Click
        Dim tmp As ChucVuDTO = New ChucVuDTO()
        tmp.MaCV = gvChucVu.CurrentRow.Cells(0).Value.ToString()

        Dim bus As ChucVuBUS = New ChucVuBUS()
        bus.Delete(tmp)
        gvChucVu_Load()
    End Sub

    Private Sub gvChucVu_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles gvChucVu.SelectionChanged
        If gvChucVu.CurrentRow IsNot Nothing Then
            txtTenCV.Text = gvChucVu.CurrentRow.Cells(1).Value.ToString()
        End If
    End Sub
End Class
